import Koa from "koa";

function apiResponse() {
  return async function name(ctx: Koa.Context, next: Koa.Next) {
    ctx.success = function (data: any, msg: string) {
      ctx.body = {
        code: 200,
        msg,
        data,
      };
    };
    ctx.fail = function (msg: string, code: number) {
      ctx.body = {
        code,
        msg,
        data: null,
      };
    };
    await next();
  };
}

export default apiResponse;
